﻿using MediatR;
using W.Purchase.API.Application.Command.ClientCommand;
using W.Purchase.Repository.Interface;

namespace W.Purchase.API.Application.CommandHandler.ClientCommandHandler
{
    public class UnitDeleteCommandHandler : IRequestHandler<UnitDeleteCommand, int>
    {
        private IUnitRepository unit;
        public UnitDeleteCommandHandler(IUnitRepository unit)
        {
            this.unit = unit;
        }

        public async Task<int> Handle(UnitDeleteCommand request, CancellationToken cancellationToken)
        {
            var list = await unit.GetModelAsync(request.UnitId);
            list.IsDelete = true;
            list.DeleteTime = DateTime.Now;
            return await unit.Update(list);
        }
    }
}
